// route_guard.dart
import 'package:flutter/material.dart';
import 'auth_provider.dart';

class RouteGuard {
  static String? redirect(BuildContext context, AuthProvider auth) {
    final routeSettings = ModalRoute.of(context)?.settings;
    final routeName = routeSettings?.name;

    // 需要登录的路由
    final protectedRoutes = [
      '/IncomingGoodsPage', 
      '/PendingReinspectionScreen', 
      '/PendingDelivery',
      '/StockingAndWarehousingPage',
      '/PickingGoods',
      '/WeighingGoods',
      '/OutboundInspection',
      '/PickupGoods',
      '/WarehouseRelocation',
      '/InventoryCheck',
      '/InventoryInquiry',
      '/InventoryLog',
      '/InstockDefects',
      '/Exchange',
      '/IncomingGoodsInquiry',
      '/PackingGoods',
      '/Home'
      ];
     print('路由守卫--,$routeName,${auth.isLoggedIn}');
    if (protectedRoutes.contains(routeName) && !auth.isLoggedIn) {
      return '/Login'; // 重定向到登录页
    }

    if (routeName == '/Login' && auth.isLoggedIn) {
      return '/Home'; // 已登录时访问登录页，重定向到首页
    }

    return null; // 允许访问
  }
}
